package com.camel.docker.utils;

import com.camel.docker.config.WebSocketServer;

import java.io.*;

public class MavenUtils {
    public static void main(String[] args) {
//        packageProject();
    }

    public static void packageProject(WebSocketServer webSocketServer, FileWriter writer) {
       if(System.getProperties().getProperty("os.name").startsWith("Windows")) {
            windowPackage(webSocketServer, writer);
       }
    }

    private static void windowPackage(WebSocketServer webSocketServer, FileWriter writer) {
        Runtime runtime=Runtime.getRuntime();
        String localRepo = PropertyUtil.getProperty("local_repo_path");
        String volum = localRepo.split(":/")[0];
        String path = localRepo.split(":/")[1];
        try {
            String [] cmd={"cmd","/C", volum + ": && cd "+ path +" && mvn clean package -Dmaven.test.skip=true -X -U"};
            Process process = runtime.exec(cmd);
            InputStream fis=process.getInputStream();
            //用一个读输出流类去读
            InputStreamReader isr=new InputStreamReader(fis);
            //用缓冲器读行
            BufferedReader br=new BufferedReader(isr);
            String line=null;
            //直到读完为止
            while((line=br.readLine())!=null)
            {
                writer.write(line + "\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
